package com.b2b2c.store.single.logic;

import java.util.Map;
import java.util.concurrent.TimeUnit;

import javax.servlet.http.HttpServletRequest;

import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;

import com.b2b2c.store.single.entity.StoreEvaluate;
import com.b2b2c.store.single.mapper.StoreEvaluateMapper;
import com.b2b2c.store.single.service.IStoreEvaluateService;

/**
 * 店铺评分
 * @author Administrator
 */
public class StoreEvaluateLogic extends AbstractLogic<StoreEvaluate, Object> implements IStoreEvaluateService<StoreEvaluate> {


	public StoreEvaluateLogic(Map<String, String> args) {
		super(args);
		// TODO Auto-generated constructor stub
	}
	
	public StoreEvaluateLogic(HttpServletRequest req) {
		super(req);
		// TODO Auto-generated constructor stub
	}
	
	/**
	 * 
	 */
	public Map<String, Map<String, String>> getValidateRule() {
		// TODO Auto-generated method stub
		
		
		return null;
	}
	
	/**
	 * 获取店铺评分
	 * @param redisTemplate
	 * @return
	 */
	public StoreEvaluate getScore(RedisTemplate<String, StoreEvaluate> redisTemplate) {
		// TODO Auto-generated method stub
		
		ValueOperations<String, StoreEvaluate> valueOption =  redisTemplate.opsForValue();
		
		int storeId = (int) this.getReq().getSession().getAttribute("store_id");
		
		String key = "scope" + storeId;
		
		StoreEvaluate data = valueOption.get(key);
//		
		if (data != null) {
			return data;
		}
		data = this.getSqlTemp().getMapper(StoreEvaluateMapper.class).getScope(storeId);
		
		valueOption.set(key, data, 60, TimeUnit.SECONDS);
		
		return data;
		
	}
}
